<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\abnormalorder\model;

class OrderProcess extends \app\BaseModel
{
    protected $name = "massage_service_abnormal_order_process";
    protected $append = ["role", "wander"];
    public function getRoleAttr($value, $data)
    {
        if(!empty($data["id"])) {
            $role_model = new OrderRole();
            $dis = ["a.process_id" => $data["id"], "a.wander_id" => 0];
            $list2 = $role_model->alias("a")->join("shequshop_school_admin b", "a.user_id = b.id AND b.status =1", "left")->where($dis)->where("a.type", "in", [2, 3])->field("a.*,b.agent_name as user_name")->group("a.user_id")->select()->toArray();
            if(!empty($list2)) {
                foreach ($list2 as &$s) {
                    if($s["type"] == 3) {
                        $s["user_name"] = "代理商";
                    }
                }
            }
            return $list2;
        }
    }
    public function getRoleData($process_id, $pass_type = 0, $order_info_id = 0)
    {
        $role_model = new OrderRole();
        $handle_model = new OrderInfoHandle();
        $roles_model = new \app\node\model\RoleList();
        $order_model = new \app\massage\model\Order();
        $abn_order_model = new OrderList();
        $info_model = new OrderInfo();
        $admin_model = new \app\massage\model\Admin();
        $dis = ["a.process_id" => $process_id, "a.pass_type" => $pass_type];
        $list2 = $role_model->alias("a")->join("shequshop_school_admin b", "a.user_id = b.id AND b.status =1", "left")->where($dis)->where("a.type", "in", [2, 3])->field("a.*,b.agent_name as user_name")->group("a.user_id")->select()->toArray();
        $order_id = $info_model->where(["id" => $order_info_id])->value("order_id");
        $order_id = $abn_order_model->where(["id" => $order_id])->value("order_id");
        $admin_id = $order_model->where(["id" => $order_id])->value("admin_id");
        if(!empty($list2)) {
            foreach ($list2 as &$s) {
                if($s["type"] == 3) {
                    $s["user_name"] = "代理商";
                }
                if(!empty($order_info_id)) {
                    if($s["type"] == 3) {
                        $user_id = $admin_model->where(["admin_id" => $admin_id])->column("id");
                        $user_id[] = $admin_id;
                        $find = $handle_model->where("user_id", "in", $user_id)->where(["order_info_id" => $order_info_id])->find();
                        if(!empty($find)) {
                            $s["user_name"] = $admin_model->where(["id" => $find["user_id"]])->value("agent_name");
                        }
                    } else {
                        $find = $handle_model->where(["user_id" => $s["user_id"], "order_info_id" => $order_info_id])->find();
                    }
                    $s["handle_status"] = !empty($find) ? $find["status"] : 1;
                    $s["deduct_cash"] = !empty($find) ? $find["deduct_cash"] : 0;
                    $s["create_time"] = !empty($find) ? $find["create_time"] : 0;
                }
                $s["role"] = $roles_model->getUserRole($s["user_id"]);
            }
        }
        return $list2;
    }
    public function getWanderAttr($value, $data)
    {
        if(!empty($data["id"])) {
            $wander_model = new OrderWander();
            $list = $wander_model->where(["process_id" => $data["id"]])->select()->toArray();
            return $list;
        }
    }
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
}

?>